﻿
@{
    Layout = null;
}

<link href="~/libs/layui-v2.9.21/layui-v2.9.21/layui/css/layui.css" rel="stylesheet" />
<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">出货单号</label>
        <div class="layui-input-inline layui-input-wrap">
            <input type="text" id="shipmentNumber" name="shipmentNumber" lay-verify="required" autocomplete="off" lay-affix="clear" class="layui-input" placeholder="请输入出货单号">
        </div>
        <label class="layui-form-label">货主编码</label>
        <div class="layui-input-inline layui-input-wrap">
            <input type="text" id="productCode" name="productCode" lay-verify="required" autocomplete="off" lay-affix="clear" class="layui-input" placeholder="请输入货主编码">
        </div>
        <div class="layui-btn-container">
            <button type="button" id="btnSeath" class="layui-btn layui-btn-normal layui-btn-sm">查询</button>
            <button type="button" class="layui-btn layui-btn-primary layui-btn-sm">重置</button>
            <button type="button" class="layui-btn layui-btn-sm" onclick="insert()">
                <i class="layui-icon layui-icon-add-1">录入</i>
            </button>
            <button type="button" class="layui-btn layui-btn-warm layui-btn-sm" lay-event="delete">
                <i class="layui-icon layui-icon-delete">批量删除</i>
            </button>
        </div>
    </div>
    <script type="text/html" id="btn">
        <button type="button" class="layui-btn layui-btn-xs" lay-event="update">
            <i class="layui-icon layui-icon-edit">编辑</i>
        </button>
        <button type="button" class="layui-btn layui-btn-xs" lay-event="delete">
            <i class="layui-icon layui-icon-delete">删除</i>
        </button>
    </script>
</form>
<table class="layui-hide" id="GetCustomerShipmentList" name="GetCustomerShipmentList"></table>

<!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
<script src="~/libs/jquery/jquery.js"></script>
<script src="~/libs/layui-v2.9.21/layui-v2.9.21/layui/layui.js"></script>
<script>

        layui.use('table', function () {
            var table = layui.table;
            var from = layui.from;
            var laydata = layui.laydata;
            // 已知数据渲染
            var inst = table.render({
                elem: '#GetCustomerShipmentList',
                url: '/CustomerShipment/GetCustomerShipmentList',
                cols: [[ //标题栏
                    { type: 'checkbox', fixed: 'left' },
                    { field: 'creatorName', title: '创建人姓名 ', width: 120 },
                    {
                        field: 'creationDate', title: '创建日期 ', width: 120,
                        templet: function (d) {
                            return d.creationDate.substring(0, 8)
                        }
                    },
                    { field: 'shipmentNumber', title: '出货单号 ', width: 120 },
                    { field: 'productCode', title: '货主编码 ', width: 120 },
                    {
                        field: 'requiredDeliveryTime', title: '要求交货时间 ', width: 120,
                        templet: function (d) {
                            return d.requiredDeliveryTime.substring(0, 8)
                        }
                    },
                    { field: 'receiver', title: '收货人姓名 ', width: 120 },
                    { field: 'receiverPhone', title: '收货人电话 ', width: 120 },
                    { field: 'receiverAddress', title: '收货人地址 ', width: 120 },
                    { field: 'transportCompany', title: '运输公司 ', width: 120 },
                    { field: 'shipmentOrderNumber', title: '发货运单号 ', width: 120 },
                    { field: 'shipmentNotes', title: '发货备注 ', width: 120 },
                    { field: 'status', title: '当前状态 ', width: 120 },
                    {  title: '操作 ', width: 160, toolbar: '#btn' }
                ]],

                //skin: 'line', // 表格风格
                //even: true,
                page: true, // 是否显示分页
                height: 500,
                limits: [5, 10, 20, 30],
                limit: 10,// 每页默认显示的数量
                where: {
                    pageIndex: 1,
                    pageSize: 10
                }
            });

            //查询
            $('#btnSeath').on('click', function () {
                table.reload('GetCustomerShipmentList', {
                    page: { curr: 1 },
                    where: {
                        shipmentNumber: $('#shipmentNumber').val(),
                        productCode: $('#productCode').val(),
                    }
                })
                return false;
            })

            //删除
            // 触发单元格工具事件
            table.on('tool(GetCustomerShipmentList)', function (obj) { // 双击 toolDouble
                var data = obj.data; // 获得当前行数据
                // console.log(obj)
                if (obj.event === 'delete') {
                    layer.confirm('确定要删除吗？', function (index) {
                        var array = [];
                        array.push(data.id)
                        deleteCustomerShipment(array);
                        layer.close(index);
                    })
                } 
                if (obj.event === 'update') {
                    // 在此处输入 layer 的任意代码
                    layer.open({
                        type: 2, // page 层类型
                        area: ['600px', '810px'],
                        title: '客户出库编辑',
                        shade: 0.6, // 遮罩透明度
                        shadeClose: true, // 点击遮罩区域，关闭弹层
                        maxmin: true, // 允许全屏最小化
                        anim: 0, // 0-6 的动画形式，-1 不开启
                        content: '/CustomerShipment/Update?id=' + data.id,
                        end: function () {
                            location.reload()
                        }
                    });
                } 
            });
            // 批量删除按钮点击事件
            $('.layui-btn-warm').on('click', function () {
                var checkStatus = table.checkStatus('GetCustomerShipmentList');
                var data = checkStatus.data;
                if (data.length === 0) {
                    layer.msg('请选择要删除的数据');
                    return;
                }
                layer.confirm('确定删除选中的 ' + data.length + ' 条数据吗？', function (index) {
                    var ids = data.map(item => item.id);
                    deleteCustomerShipment(ids);
                    layer.close(index);
                });
            });

        });


    var deleteCustomerShipment = function (ids) {
        $.ajax({
            type: 'get',
            url: '/CustomerShipment/DeleteCustomerShipment',
            dataType: 'json',
            data: { ids: ids.toString() },
            success: function (res) {
                if (res > 0) {
                    layer.msg('删除成功')
                    return false;
                    location.href ='/CustomerShipment/CustomerShipmentList'
                }
            }
        })
    }

    function insert() {
        // 在此处输入 layer 的任意代码
        layer.open({
            type: 2, // page 层类型
            area: ['600px', '810px'],
            title: '客户出库录入',
            shade: 0.6, // 遮罩透明度
            shadeClose: true, // 点击遮罩区域，关闭弹层
            maxmin: true, // 允许全屏最小化
            anim: 0, // 0-6 的动画形式，-1 不开启
            content: '/CustomerShipment/Add'
        });
    }

</script>


